<template>
    <div>
        <el-table :data="list" border style="width: 100%">
            <el-table-column prop="name" label="姓名" width="180"></el-table-column>
            <el-table-column prop="phone" label="电话" width="180"></el-table-column>
            <el-table-column prop="web" label="网址" width="180"></el-table-column>
            <el-table-column prop="note" label="备注"></el-table-column>
            <el-table-column prop="state" label="状态"></el-table-column>
            <el-table-column prop="addr" label="地址"></el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">审核</el-button>
                </template>
            </el-table-column>
        </el-table>

        <!-- 弹出框 -->
        <div>
            <el-dialog
                title="提示"
                :visible.sync="dialogVisible"
                width="30%"
                :before-close="handleClose"
            >
                <span>审核信息</span>
                <el-form
                    :model="ruleForm"
                    :rules="rules"
                    ref="ruleForm"
                    label-width="100px"
                    class="demo-ruleForm"
                >
                    <el-form-item label="状态" prop="state">
                        <el-input v-model="ruleForm.state"></el-input>
                    </el-form-item>
                    <el-form-item label="评语" prop="comments">
                        <el-input type="textarea" v-model="ruleForm.comments"></el-input>
                    </el-form-item>
                </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="dialogVisible = false">取 消</el-button>
                    <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
                </span>
            </el-dialog>
        </div>
    </div>
</template>

<script>
import { getListAll } from '../../../api/supplier';
import { mapState, MapActions, mapActions } from 'vuex';
import Axios from 'axios';
export default {
    data() {
        return {
            list: [],
            dialogVisible: false,
            ruleForm: {
                state: '',
                comments: '',
                _id: ''
            }
        };
    },
    computed: {
        ...mapState('supplier', ['tableData'])
    },
    created() {
        this.getList();
    },
    methods: {
        handleEdit(index, row) {
            this.dialogVisible = true;
            console.log(row.state);

            this.ruleForm.state = row.state;
            this.ruleForm._id = row._id;
        },
        submitForm(formName, row) {
            this.dialogVisible = false;
            const _id = this.ruleForm._id;
            Axios({
                method: 'patch',
                url: `/api/supplier/audit/${_id}`,
                data: {
                    state: this.ruleForm.state,
                    comments: this.ruleForm.comments
                }
            }).then(res => {
               this.getList();
            });
        },
        async getList() {
            const data = await getListAll();
            this.list = data.rows;
        }
    }
};
</script>

<style></style>
